package com.kxf.alarmmanagertest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.kxf.utils.Util;

public class MyReceiver extends BroadcastReceiver {
    public static final String TAG = "MyReceiver";
    public static MyAlarmManager myAlarmManager;

    MyReceiver.Listener listener = new MyReceiver.Listener() {
        public void callback(Intent intent) {
            int type = intent.getIntExtra("type", 0);
            switch (type) {
                case 1:
                    myAlarmManager.startAlarmManagerExact();
                    break;
                case 2:
                    myAlarmManager.startAlarmManagerWindow();
                    break;
                case 3:
                    myAlarmManager.startAlarmManagerAndAllowWhileIdle();
                    break;
                case 4:
                    myAlarmManager.startAlarmManagerExactAndAllowWhileIdle();
                    break;

            }
        }
    };

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "AlarmManager BroadcastReceiver intent=" + Util.getIntentExtrasToString(intent));
        listener.callback(intent);
    }

    interface Listener {
        void callback(Intent intent);
    }
}